﻿using Rhino.Display;
using Rhino.Geometry;
using System.Drawing;

namespace AiMoInGH.ScriptInstance.Preview
{
    class PreviewPlane : PreviewObject
    {
        Plane plane;
        public PreviewPlane(Plane plane, Color color) : base(color)
        {
            this.plane = plane;

        }
        public override void Draw(DisplayPipeline display)
        {
            display.Viewport.GetWorldToScreenScale(plane.Origin, out double pixelsPerUnit);
            double scale = 20 / pixelsPerUnit;
            display.DrawLine(plane.Origin, plane.Origin + plane.XAxis * scale, Color.Red);
            display.DrawLine(plane.Origin, plane.Origin + plane.YAxis * scale, Color.Green);
            display.DrawLine(plane.Origin, plane.Origin + plane.ZAxis * scale, Color.Blue);
            scale *= 0.5;
            Hatch hatch = Hatch.Create(new PolylineCurve(new Point3d[] { plane.Origin, plane.PointAt(scale, 0), plane.PointAt(scale, scale), plane.PointAt(0, scale), plane.Origin }), 0, 0, 1, 0.1)[0];
            display.DrawHatch(hatch, DrawColor, DrawColor);
        }
    }
}
